package chapter17;

import java.util.*;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/3/24 15:17
 */
class Data {
    private int anInt;
    private String data;

    public Data() {
    }

    public Data(int anInt, String data) {
        this.anInt = anInt;
        this.data = data;
    }

    public int getAnInt() {
        return anInt;
    }

    public void setAnInt(int anInt) {
        this.anInt = anInt;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Data{" +
                "anInt=" + anInt +
                ", data='" + data + '\'' +
                '}';
    }
}

public class ReadOnly {
    static Collection<String> data = new ArrayList<>(Arrays.asList("one two three four five six".split(" ")));

    public static void main(String[] args) {
        Collection<String> c = Collections.unmodifiableCollection(data);
        System.out.println(c);

        List<String> a = Collections.unmodifiableList(new ArrayList<>(data));
        ListIterator<String> it = a.listIterator();
        System.out.println(it.next());

        //UnsupportedOperationException
//        a.set(1, "new");

        List<Data> dataList = new ArrayList<>(Arrays.asList(new Data(1, "aa"), new Data(2, "bb")));

        List<Data> unChange = Collections.unmodifiableList(dataList);

        dataList.get(0).setData("new");

        System.out.println(unChange);
    }
}
